package com.itlong.cloud.controller.finance;

import com.itlong.cloud.POJO.DTO.property.PropertyPaymentTradeGetPageDTO;
import com.itlong.cloud.POJO.VO.MessageVO;
import com.itlong.cloud.POJO.VO.property.PropertyPaymentTradeInfoAllVO;
import com.itlong.cloud.abstracts.BaseController;
import com.itlong.cloud.annotation.AuthAccessRequired;
import com.itlong.cloud.enumerate.ecode.BaseErrorCodeEnum;
import com.itlong.cloud.paymenthub.IPaymentTradeServiceClient;
import com.itlong.cloud.thrown.DataAccessException;
import com.itlong.cloud.utils.network.http.HttpProtocolUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * <desc>
 *      运营-财务管理-直接到账的支付订单管理
 * </desc>
 *
 * @createDate2019/10/23
 **/
@RestController
@RequestMapping("/finance/directPaymentTrade")
public class OperatePaymentTradeController extends BaseController {

    @Autowired
    private IPaymentTradeServiceClient iPaymentTradeServiceClient;

    /**
     * <desc>
     *      查询直接到账的支付订单
     * </desc>
     *
     * @param propertyPaymentTradeGetPageDTO
     * @return
     * @Author Zhu.yj
     * @createDate  2019/10/23
     */
    @ResponseBody
    @AuthAccessRequired
    @RequestMapping(path = "getOperatePaymentTradeByPage",method = RequestMethod.POST)
    public Object getOperatePaymentTradeByPage(PropertyPaymentTradeGetPageDTO propertyPaymentTradeGetPageDTO){
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            propertyPaymentTradeGetPageDTO = HttpProtocolUtil.parseRequestParamToDTO(PropertyPaymentTradeGetPageDTO.class, request);
            if(propertyPaymentTradeGetPageDTO==null){
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }

            PropertyPaymentTradeInfoAllVO propertyPaymentTradeGetPageInfoAllVO = iPaymentTradeServiceClient.getOperatePaymentTradeByPage(propertyPaymentTradeGetPageDTO);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),propertyPaymentTradeGetPageInfoAllVO);
        }
        catch (Exception e){
            throw new DataAccessException("【运营-财务管理-getOperatePaymentTradeByPage】分页获取直接到账的支付订单失败",e);
        }
    }
    
}
